'''
Created on Jan 10, 2010

@author: Berin
'''
from surfacegrid import SurfaceGrid
import pygame
class PaintGrid(SurfaceGrid):
	'''
	classdocs
	'''

	def __init__(self, windowHeight, windowWidth, startPosition):
		'''
		Constructor
		'''
		SurfaceGrid.__init__(self, 0, 0, 0, 0, None)

		self.listArray = []
		self.boundArray = []
		
		self.surface_setup(windowHeight, windowWidth, startPosition)
		

	def surface_setup(self, windowHeight, windowWidth, startPosition):
		self.height = ((windowHeight - 32) // 32) * 32
		self.width = ((windowWidth - startPosition - 32*2) // 32) * 32
		self.center_distance_width = startPosition + (32*2)
		self.mainSurface = pygame.Surface((self.width, self.height))
		self.mainSurface.fill((255,255,255))
		
		self.grid = self.gridsurface_setup(self.mainSurface)
		
	def gridsurface_setup(self, surface):
		temp = surface.copy()
		temp.set_colorkey((255,255,255))
		left = 0
		top = 0
		while top < temp.get_height():
			while left < temp.get_width():
				pygame.draw.rect(temp, (140,140,140), pygame.Rect(left, top, 32, 32), 1)
				left = left + 32
			left = 0
			top = top + 32
		return temp
	
	def draw(self):
		'''
		Draws the Tiles
		'''
		SurfaceGrid.draw(self)
		
		'''
		Do other drawing below
		'''
	
		for slices in self.listArray:
			for elevated in slices.get_Surface():
				self.mainSurface.blit(elevated, (slices.get_X() - self.xPosition, slices.get_Y() - self.yPosition))
		
		self.mainSurface.blit(self.grid, (0,0))
		
		for rect in self.boundArray:
			rect = pygame.Rect(rect.left - self.xPosition, rect.top - self.yPosition, rect.width, rect.height)
			pygame.draw.rect(self.mainSurface, (255,0,0), rect, 1)
		
		
		

#	def surface_setup(self):
#		left = 0
#		top = 0
#			
#		surfset_height = ((self.window.get_height() - 32) // 32) * 32
#		
#		self.center_distance_width = self._tileSelectorGrid.width + (32*2)
#		self.paintset_width = ((self.window.get_width() - self._tileSelectorGrid.width - 32*2) // 32) * 32
#		
#		self.paintset_surf = pygame.Surface((self.paintset_width, surfset_height))
#		self.paintset_surf.fill((255,255,255))
#		
#		self.paintset_grid = self.gridsurface_setup(self.paintset_surf)
#		
#		self._tileSelectorGrid.surface_setup(self.window.get_height())